package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Check {
	
	/**
	 * 鍦ㄧ櫥褰曟椂锛� 楠岃瘉璐﹀彿瀵嗙爜鏄惁姝ｇ‘
	 */
	public boolean  check1(String countname,String pwd) throws IOException{
		
		File file=new File("Message.txt");   //鍒涘缓鏂囦欢绫�
        if(!file.exists()||file.isDirectory()) //鍒ゆ柇鏂囦欢鏄惁瀛樺湪
            //throw new FileNotFoundException();
        	file.createNewFile();
        BufferedReader br=new BufferedReader(new FileReader(file)); //鍒涘缓璇诲叆缂撳啿娴侊紝鎸夎璇诲叆
        String temp=null;   
       // StringBuffer sb=new StringBuffer();   
        temp=br.readLine();   //鍏堣鍙栦竴琛�
        while(temp!=null){
        	String sbstring = temp.toString();   //杞寲涓簊tring
        	int n = sbstring.length();            //娴嬪瓧绗︿覆闀垮害
        	String []message = new String[5];     //鎸墌鎷嗗垎 鎴�5涓瓧绗︿覆鏁扮粍锛屾寜璐﹀彿鍜屽瘑鐮佽繘琛屼俊鎭獙璇�
        	int k=0;
        	
        	for (int i=0; i<2; i++)
        		message[i]="";
        	//鎴戜滑鍦ㄥ啓鍏ョ敤鎴锋椂鐢▇鍒嗗壊锛� 鎵�浠ユ垜浠埄鐢▇鍦ㄥ垎鍓插紑鏉�
        	for (int i=0; i<n; i++)
        	{
        		if(sbstring.charAt(i)=='~')
        		{
        			System.out.println("@"+message[k]+"-----------");
        			k++;
        		}
        		else 
        		{
        			message[k] += sbstring.charAt(i);
        		}
        	}
        	if (countname.equals(message[0])&&pwd.equals(message[1]))//姣旇緝璐︽埛瀵嗙爜鏄惁鐩哥瓑
        		return true;
            temp=br.readLine();  //璇诲彇涓嬩竴琛�
        }
        return false;
			
		
	}
	
	//鍦ㄦ敞鍐屾椂 楠岃瘉璐﹀彿鏄惁瀛樺湪
	public boolean  check2(String countname) throws IOException{
		
		File file=new File("Message.txt");   //鍒涘缓鏂囦欢绫�
        if(!file.exists()||file.isDirectory()) //鍒ゆ柇鏂囦欢鏄惁瀛樺湪
        	file.createNewFile();
        BufferedReader br=new BufferedReader(new FileReader(file)); //鍒涘缓璇诲叆缂撳啿娴侊紝鎸夎璇诲叆
        String temp=null;   
       // StringBuffer sb=new StringBuffer();   
        temp=br.readLine();   //鍏堣鍙栦竴琛�
        while(temp!=null){
        	String sbstring = temp.toString();   //杞寲涓簊tring
        	int n = sbstring.length();            //娴嬪瓧绗︿覆闀垮害
        	String []message = new String[5];     //鎸墌鎷嗗垎 鎴�5涓瓧绗︿覆鏁扮粍锛屾寜璐﹀彿鍜屽瘑鐮佽繘琛屼俊鎭獙璇�
        	int k=0;
        	
        	for (int i=0; i<5; i++)
        		message[i]="";
        	for (int i=0; i<n; i++)
        	{
        		if(sbstring.charAt(i)=='~')
        		{
        			System.out.println("@"+message[k]+"***************");
        			k++;
        		}
        		else 
        		{
        			message[k] += sbstring.charAt(i);
        		}
        	}

        	if (!countname.equals(message[0])) {
        		System.out.println("true");
        		return true;
        	}
        		
            temp=br.readLine();
        }
        System.out.println("false");
        return false;
	}

	//楠岃瘉鐢ㄦ埛鍚嶅拰瀵嗙爜鏄惁涓轰腑鏂�
	public boolean checkcountname(String countname)
	{
		 Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
	        Matcher m = p.matcher(countname);
	        if (m.find()) {
	            return true;
	        }
	        return false;
	}
	//楠岃瘉濮撳悕鏄惁涓轰腑鏂�
	public boolean checkname(String name)
	{
		int n = 0;
	    for(int i = 0; i < name.length(); i++) {
	        n = (int)name.charAt(i);
	        if(!(19968 <= n && n <40869)) {
	            return false;
	        }
	    }
	    return true;
	}
}


